package com.easyui.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.easyui.bean.*;
import com.easyui.common.*;

public class ShowSProjectServlet extends HttpServlet {

	public ShowSProjectServlet() {}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/json;charset=utf-8");
		response.setCharacterEncoding("UTF-8");
		request.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		
		List<Map> initList = null;
		JSONArray jsonProject = null;
		
		String sno = request.getParameter("sno");
		
		
		HttpSession session = request.getSession(); //获的session
		String role = (String)session.getAttribute("role");
		String userID = (String)session.getAttribute("userID");
		
		if(role != null && !role.trim().equals("")) {
			if(userID != null && !userID.trim().equals("")) {
				initList = new SelProject().getSProjects(sno);
			}
		}
		
		if (initList != null && initList.size() > 0) {
			jsonProject = new JSONArray();
			for (int i = 0; i < initList.size(); i++) {
				Map<String, Object> m = initList.get(i);
				
				JSONObject j = new JSONObject();
				j.put("pno", m.get("pno"));
				j.put("pname", m.get("pname"));
				j.put("pubname", m.get("tname"));
				j.put("progress", m.get("progress"));
				j.put("stage", m.get("stage"));
				
				jsonProject.add(j);
			}
		}
			
		
		out.print(jsonProject);
		out.flush();
		out.close();
	}


}
